package com.wangtao.firstapp.custom;

import android.app.Dialog;
import android.content.Context;
import android.os.Handler;
import android.view.Window;
import android.view.WindowManager;

import com.wangtao.firstapp.R;

/**
 * 自定义DiaLog，用于展示 收藏和取消收藏
 * Created by lanouhn on 16/9/6.
 */
public class CollectDialog extends Dialog {

    private Window window = null;

    public CollectDialog(Context context) {
        super(context);
    }

    public CollectDialog showDialog(int layoutResID, int x, int y) {
        setContentView(layoutResID);

        windowDeploy(x, y);

        //设置 对话框 自动消失
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                dismiss();
            }
        },1000);
        //设置触摸对话框意外的地方取消对话框
        //setCanceledOnTouchOutside(true);

        show();
        return null;
    }

    Handler handler = new Handler() {

    };

    //设置窗口显示
    public void windowDeploy(int x, int y) {
        window = getWindow(); //得到对话框
        window.setWindowAnimations(R.style.dialogWindowAnim); //设置窗口弹出动画
        window.setBackgroundDrawableResource(R.color.vifrification); //设置对话框背景为透明
        WindowManager.LayoutParams wl = window.getAttributes();
        //根据x，y坐标设置窗口需要显示的位置
        wl.x = x; //x小于0左移，大于0右移
        wl.y = y; //y小于0上移，大于0下移
//            wl.alpha = 0.6f; //设置透明度
//            wl.gravity = Gravity.BOTTOM; //设置重力
        window.setAttributes(wl);
    }
}
